/**
 * Created by Administrator on 2014/11/17.
 */

//左边菜单的template
indexModule.directive("sidebar",function(){
    return {
        restrict: 'E',
        templateUrl: "/templates/sidebar.html",
        replace: true
    }
})

//菜单列表的配置
indexModule.controller('sidebar',function($scope,$location){
    $scope.menu = [
        {
            parent:"网站广告",
            icon: "icon4",
            parent_cur: "",
            chrildren_show: "",
            urls:[
                {name:"网站列表",link:"#/web/list",val:"web/list"}]
        },
        {
            parent:"站长留言",
            icon: "icon2",
            parent_cur: "",
            chrildren_show: "",
            urls:[
                {name:"我的留言",link:"#/talk/list",val:"talk/list"},
                {name:"我要留言",link:"#/talk/add",val:"talk/add"}]
        },
        {
            parent:"公告",
            icon: "icon5",
            parent_cur: "",
            chrildren_show: "",
            urls:[
                {name:"公告列表",link:"#/notice/list",val:"notice/list"},
                {name:"发表公告",link:"#/notice/add",val:"notice/add"}]
        },
        {
            parent:"所有资源",
            icon: "icon1",
            parent_cur: "",
            chrildren_show: "",
            urls:[
                {name:"所有留言",link:"#/article/talk",val:"article/talk"},
                {name:"所有公告",link:"#/article/notice",val:"article/notice"},
                {name:"广告分享",link:"#/article/ad",val:"article/ad"},
                {name:"教程视频",link:"#/article/video",val:"article/video"}]
        },
        {
            parent:"用户管理",
            icon: "icon3",
            parent_cur: "",
            chrildren_show: "",
            urls:[{name:"用户列表",link:"#/users/list",val:"users/list"}]
        }
    ];

    $scope.sidebarFun = function(page,index){
        var current = $location.path().substring(1);
        //if(page.indexOf(current) != -1){
        if(page.indexOf(current) != -1){
            $scope.menu[index].parent_cur = "cur";
            $scope.menu[index].chrildren_show = "showed";
            return "cur";
        }else if(current.indexOf(page[0]) != -1){
            $scope.menu[index].parent_cur = "cur";
            $scope.menu[index].chrildren_show = "showed";
            return "cur";
        }
    };
});

$(document).ready(function(){
    //左侧导航效果
    $("html").delegate("#sidebar a","click",function(){
        $(this).addClass("cur").siblings().removeClass("cur");
        if(($(this).attr("class")).indexOf("parent") != -1){
            $(this).parent().siblings().children(".children").children("a").removeClass("cur");
        }else{
            $(this).parent().parent().siblings().children(".children").children("a").removeClass("cur");
        }
        $(this).parents(".sidebar-menu").siblings().removeClass("cur");
        $(this).parents(".sidebar-menu").siblings().children(".children").fadeOut(300);
    });
    $("html").delegate("#sidebar .parent","click",function(){
        if(($(this).parent().prop("class")).indexOf("cur") != -1){
            $(this).parent().removeClass("cur");
        }else{
            $(this).parent().addClass("cur");
        }
        $(this).siblings(".children").toggle(300);
    });
})
